/* eslint-disable class-methods-use-this */
import {
  get,
  post,
  put,
  _delete,
} from '@/lin/plugins/axios'

// 我们通过 class 这样的语法糖使模型这个概念更加具象化，其优点：耦合性低、可维护性。
class Product {
  // constructor() {}
  async getProductList(page, limit, info) {
    const res = await get(`v1/product?page=${page}&limit=${limit}`, info)
    return res
  }

  async getProductTypeAll() {
    const res = await get('v1/product-type/all')
    return res
  }

  async getProductTypeList(page, limit, info) {
    const res = await get(`v1/product-type?page=${page}&limit=${limit}`, info)
    return res
  }

  async getProductInfo(id) {
    const res = await get(`v1/product/${id}`)
    return res
  }

  async createProduct(info) {
    const res = await post('v1/product', info)
    return res
  }

  async createProductType(info) {
    const res = await post('v1/product-type', info)
    return res
  }

  async updateProduct(info) {
    const res = await put('v1/product', info)
    return res
  }

  async updateProductType(info) {
    const res = await put('v1/product-type', info)
    return res
  }

  async deleteProduct(id) {
    const res = await _delete(`v1/product/${id}`)
    return res
  }

  async upDownProduct(info) {
    const res = await put('v1/up-down/product', info)
    return res
  }
}

export default new Product()
